<?php
include_once('Publication.php');



function calcHindex ($orgID, $yearStart, $yearEnd, $domainID, $subDomainID) {

    ini_set('max_execution_time', 3000);
    
    $pub = new Publication;
    $pub->orderBy = "CitationCount";
  
    $pub->orgID = $orgID; 
    
    if ($domainID !=0) 
    {
        $pub->domainID = $domainID;
    }
   
    if ($subDomainID !=0) 
    {
        $pub->subDomainID = $subDomainID;
    }
    
    $pub->yearStart = $yearStart;
    $pub->yearEnd = $yearEnd;
    
    /*$pub->startIdx = 1;
    $pub->endIdx = 100;*/
    
    $hIdx = 0;
    $iteration = 1;
    for ($i=3;$i<1401;$i+=100)
    {       
         $pub->startIdx = $i;
         $pub->endIdx = $i+99;
         $pub->makeQuery();
         for ($j=0;$j<100;$j++) {
         
        
         
         if ($pub->getCitations($j) < ($j + $iteration)) 
         {
             $hIdx = $j + $iteration + 1; //silly fix cause we start at 3 //- 1;
             break;
         }
        }
        if ($hIdx > 0)
        {
            break;
        }
        $iteration +=100;
    }
    
    return $hIdx;
}

?>